<?php
namespace Systemht\Controller;
use Think\Controller;
class LinkController extends IndexController{
	public function index(){
		$model = M('Link');
		$count = $model->count();
		$Page       = new \Think\Page($count,C('PAGE_NUM'));
		$show       = $Page->Homeshow();
		$Page->lastSuffix = false;
		$this->assign('show',$show);
		//分页查询数据
		$data = $model->order('sort ASC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('data',$data);
		$this->display();
	}
	public function add(){
		if(IS_POST){
			$model = D('Link');
			if($model->create(I('post.'),1)){
				if($model->add()){
					$this->success('添加成功',U('add'));
					exit;
				}
			}
			$this->error($model->getError());
		}
		$this->display();
	}
	public function edit(){
		$model = D('Link');
		if(IS_POST){
			if($model->create(I('post.'),2)){
				if(false !== $model->save()){
					$this->success('修改成功',U('index'));
					exit;
				}
			}
			$this->error($model->getError());
		}
		$id = I('get.id');
		$data = $model->where(array('id'=>$id))->find();
		$this->assign('data',$data);
		$this->display();
	}
	public function del(){
		$id = I('post.id');
		$result = M('Link')->where(array('id'=>$id))->delete();
		if($result){
			$this->ajaxReturn(array('status'=>"OK",'msg'=>'删除成功'));
		}
		else{
			$this->ajaxReturn(array('status'=>"NO",'msg'=>'删除失败'));
		}
	}
}